import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../utils/Settings.dart';
import 'LQueryFormLogic.dart';
import 'LQueryFormState.dart';

class LQueryFormPage extends StatelessWidget {

  const LQueryFormPage({super.key, required this.tag});
  final String tag;


  @override
  Widget build(BuildContext context) {
    final LQueryFormState state = Get.find<LQueryFormLogic>(tag: tag).state;
    state.tag = tag;


    return GetBuilder<LQueryFormLogic>(
        // assignId:true,
        // autoRemove:true,
        tag: tag,
        // id: state.id,
        builder: (logic){
          return Stack(
            children: [
              SingleChildScrollView(
                  child: Column(
                    children: [
                      Form(
                        key: state.formKey,
                        child: Column(
                            crossAxisAlignment:CrossAxisAlignment.start,
                            children: logic.createFormItes()
                        ),
                      ),
                      const SizedBox(height: 50,),
                    ],

                  )
              ),
              Positioned(
                left: 10,
                right: 10,
                bottom: 0,
                child: Padding(
                    padding: const EdgeInsets.only(left: 10,right: 10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        state.isCanReset?SizedBox(
                          width: MediaQuery.of(context).size.width * 0.4,
                          child: OutlinedButton(

                            style: ButtonStyle(
                              backgroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                                return Colors.black26;
                              }),
                              foregroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                                return Colors.white;
                              }),
                            ),
                            onPressed:(){
                              logic.reset();
                            },
                            child: const Text('重置',style: TextStyle(fontSize: 16,)),

                          ),
                        ):const SizedBox(),
                        state.isCanReset?SizedBox(
                          width: MediaQuery.of(context).size.width * 0.4,
                          child: OutlinedButton(
                            style: ButtonStyle(
                              backgroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                                return Settings.primaryColor;
                              }),
                              foregroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                                return Colors.white;
                              }),
                            ),
                            onPressed:(){
                              logic.query();
                            },
                            child: const Text('确定',style: TextStyle(fontSize: 16,)),

                          ),
                        ):SizedBox(
                          width: MediaQuery.of(context).size.width * 0.8,
                          child: OutlinedButton(
                            style: ButtonStyle(
                              backgroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                                return Settings.primaryColor;
                              }),
                              foregroundColor: MaterialStateProperty.resolveWith<Color>((states) {
                                return Colors.white;
                              }),
                            ),
                            onPressed:(){
                              logic.query();
                            },
                            child: const Text('确定',style: TextStyle(fontSize: 16,)),

                          ),
                        )

                      ],
                    )
                ),
              )
            ],
          );

        }
    );
  }

}